<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>

    <style>
    body{background-color: #fcfcfc;}
    a{color:#000;}
    .header{ width:100%; height:110px;}
    .header img{width:100px; height:100px;border-radius: 50px;border: none;float: left;margin-left: 25px;margin-top: 10px;}
    .header span{line-height: 120px;float:left;font-size: 20px;margin-left: 10px;}
    .main{width:100%;height:auto;}
    .tab{float: left;width:100%;}
    .tab li{width:100%;padding-left: 20px;height:45px;line-height: 45px;border-bottom: 2px solid #f2f2f2;font-weight: 700;font-size: 18px;color: #0082E4;}
    .tab li img{width:34px;height:34px;float: left;margin: 6px 8px 0 0;}

    </style>
</head>
<body>

    <div class="header" id="header"></div>

    <!--没有用户时的代码 <div class="header">
      <img src="../image/wutouxiang.png" alt="">
      <span><a href="./my/ligin.html">登录</a>|
      <a href="./my/register.html">注册</a></span>
    </div> -->
    <div class="main">
      <ul class="tab">
        <li class="one" onclick="Win_grxx();"><img src="../image/wd_grxx.png" alt="">个人信息</li>
        <li onclick="Win_cydz();"><img src="../image/wd_cydz.png" alt="">常用地址</li>
        <li onclick="Win_wddd();"><img src="../image/wd_wddd.png" alt="">我的商品订单</li>
        <li onclick="Win_wdshdd();"><img src="../image/wd_wddd.png" alt="">我的顺捎订单</li>
        <li onclick="Win_shoppingcart();"><img src="../image/shoppingcart.png" alt="">我的购物车</li>
        <li onclick="Win_zcshr();"><img src="../image/wd_zcshr.png" alt="">注册捎货人</li>
        <li onclick="Win_wdye();"><img src="../image/wd_wdye.png" alt="">我的余额</li>
        <li onclick="Win_wdsp();"><img src="../image/wd_fbsp.png" alt="">我的商品</li>
        <li onclick="Win_fbsp();"><img src="../image/wd_fbsp.png" alt="">发布商品</li>
        <li onclick="Win_sz();"><img src="../image/wd_sz.png" alt="">设置</a></li>
      </ul>
    </div>
</body>

<script type="text/javascript" src="../script/SHA1.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/x-dot-template"id="tmpl-1">
{{? it[0].Headpicture!=null}}
<img id="touxiang" src="{{=it[0].Headpicture.url}}" onClick="change_user()"/>
{{??}}
<img id="touxiang" src="../image/sxlogo.png" onClick="change_user()"/>
{{?}}
<span id="user">{{=it[0].username}}</span>
</script>

<script type="text/javascript">
   apiready= function(){

     //获取已登入用户id
     userInfor= $api.getStorage('userInfor');
     //获取X-APICloud-AppKey值
     var now = Date.now();
     appKey = SHA1("A6032422409194"+"UZ"+"808CF36B-60D4-DC5D-C9F3-FB49F9E1FB44"+"UZ"+now)+"."+now

    //这是查询的过滤条件
    var params = {
        fields: {},
        include:'address',
        where: {
            id:userInfor.userId
        },
        skip: 0,
        limit: 20
    }


      //将json转换成string
      params = $api.jsonToStr(params);


     api.ajax({
         url: 'https://d.apicloud.com/mcm/api/user?filter=' + params,
         method: 'GET',
         cache:  false,
         headers:{
           "X-APICloud-AppId": "A6032422409194",
           "X-APICloud-AppKey": appKey
         }
     },function(ret, err){
         if (ret) {
             $api.setStorage('user', ret);
             //使用doT模板将用户信息放入html中
             // 编译模板函数
             tmpltxt=doT.template(document.getElementById("tmpl-1").innerHTML);//生成模板方法
             document.getElementById("header").innerHTML=tmpltxt(ret);//数据渲染
         } else {
             api.alert({
                 title: '警告',
                 msg: '数据库连接失败',
             }, function(ret, err){});
         }
     });

     init_listenevent();
   }

   function init_listenevent(){
     api.addEventListener({
         name: 'updateuser'
     }, function(ret, err){
         if( ret ){
           //使用doT模板将用户信息放入html中
           // 编译模板函数
           tmpltxt=doT.template(document.getElementById("tmpl-1").innerHTML);//生成模板方法
           document.getElementById("header").innerHTML=tmpltxt(ret.value.user);//数据渲染
         }else{
              alert("数据库连接失败");
         }
     });
   }

   function change_user(){

     api.openWin({
         name: 'edituserinfor',
         url: './my/edituserinfor.html'
     });
   }

  function Win_wdshdd(){
    api.openWin({
            name: 'wdshdd',
            url: './my/wdshdd.html',
            opaque: true,
            vScrollBarEnabled: false
    });
  }

	function Win_grxx() {
		api.openWin({
		        name: 'grxx',
		        url: './my/grxx.html',
		        opaque: true,
		        vScrollBarEnabled: false
		});
	}

  function Win_cydz() {
    api.openWin({
            name: 'cydz',
            url: './my/cydz.html',
            opaque: true,
            vScrollBarEnabled: false
    });
  }
  function Win_wddd() {
		api.openWin({
		        name: 'wddd',
		        url: './my/wddd.html',
		        opaque: true,
		        vScrollBarEnabled: false
		});
	}
  function Win_shoppingcart(){
    api.openWin({
            name: 'wddd',
            url: './my/shoppingcart.html',
            opaque: true,
            vScrollBarEnabled: false
    });
  }
  function Win_zcshr() {
    var user = $api.getStorage('user');
    if(!user[0].isdelivery){
		api.openWin({
		        name: 'zcshr',
		        url: './my/zcshr.html',
		        opaque: true,
		        vScrollBarEnabled: false
		});
  }else {
    alert('已经注册为捎货人，去接单吧！！')
  }
	}
  function Win_wdye() {
		api.openWin({
		        name: 'wdye',
		        url: './my/wdye.html',
		        opaque: true,
		        vScrollBarEnabled: false
		});
	}
  function Win_wdsp() {
    api.openWin({
            name: 'wdsp',
            url: './my/wdsp.html',
            opaque: true,
            vScrollBarEnabled: false
    });
  }
  function Win_fbsp() {
		api.openWin({
		        name: 'fbsp',
		        url: './my/fbsp.html',
		        opaque: true,
		        vScrollBarEnabled: false
		});
	}
  function Win_sz() {
    api.openWin({
            name: 'sz',
            url: './my/sz.html',
            opaque: true,
            vScrollBarEnabled: false
    });
  }

</script>

</html>
